﻿<!DOCTYPE html>
<html>
<head>
    <script src="/js/header.js"></script>
</head>
<body>
<section class="container-fluid" style="background-color: white;height:535px">
    <form class="form-horizontal m15_t" id="form" onsubmit="return false;">
        <div class="row m15_t" id="header">

            <div class="tab-content col-md-3">
                <a href="#head"></a>
                <input type="hidden" id="hdCompanyPId" name="hdCompanyPId" value="0">

                <div class="tab-pane fade in active" id="divBankInfo">

                    <div class="form-group">
                        <label class="wd125 control-label"><span class="WdateFmtErr">*</span>银行代码：</label>
                        <div class="">
                            <input class="form-control wd250" type="text" name="BankCode" id="BankCode" maxlength="40" placeholder="长度必须介于 1 和 40 之间" autocomplete="off">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="wd125 control-label"><span class="WdateFmtErr">*</span>银行名称：</label>
                        <div class="">
                            <input class="form-control wd250" type="text" name="BankName" maxlength="40" placeholder="长度必须介于 1 和 40 之间" autocomplete="off">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="wd125 control-label">银行全部名称：</label>
                        <div class="">
                            <input class="form-control wd250" type="text" name="BankFullName" maxlength="40" placeholder="长度必须介于 1 和 40 之间" autocomplete="off">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="wd125 control-label">银行英文名称：</label>
                        <div class="">
                            <input class="form-control wd250" type="text" name="BankEnglishName" maxlength="40" placeholder="长度必须介于 1 和 40 之间" autocomplete="off">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="wd125 control-label">银行网址：</label>
                        <div class="">
                            <input class="form-control wd250" type="text" name="BankUrl" maxlength="400" placeholder="长度必须介于 1 和 400 之间" autocomplete="off">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="wd125 control-label">银行说明：</label>
                        <div class="">
                            <textarea class="form-control wd250" type="text" id="BankRemark" name="BankRemark" maxlength="200"></textarea>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="wd125 control-label">银行电话：</label>
                        <div class="">
                            <input class="form-control wd250" type="text" name="BankTel" maxlength="40" placeholder="长度必须介于 3 和 40 之间" autocomplete="off">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="wd125 control-label">银行地址：</label>
                        <div class="">
                            <textarea class="form-control wd250" type="text" id="BankAddress" name="BankAddress" maxlength="200"></textarea>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="wd125 control-label">排序：</label>
                        <div class="">
                            <input class="form-control wd250" type="text" name="SortNo" maxlength="10" value="0" autocomplete="off">
                        </div>
                    </div>

                </div>
            </div>

        </div>
    </form>
</section>
<script type="text/javascript">
    var validator = null;

    $(function () {
        var id = FlashPay.Util.GetQueryString("id");//SortNo

        if (id != null && id != undefined) {
            showBankInfo(id);
        }
        validator = FlashPay.Util.Validator({
                formObj: $("#form"),
                rules: {
                    BankCode: {
                        required: true,
                        specialChar: true,
                        rangelength: [1, 40]
                    },
                    BankName: {
                        required: true,
                        specialChar: true,
                        rangelength: [1, 40]
                    },
                    BankFullName: {
                        specialChar: true
                    },
                    BankEnglishName: {
                        specialChar: true
                    },
                    BankTel: {
                        isPhone: true
                    },
                    SortNo: {
                        required: true,
                        IsPositiveInteger: true
                    }
                },
                messages: {
                    BankCode: {
                        required: "必须填写银行代码",
                        rangelength: "银行代码长度必须介于 1 和 40 之间"
                    },
                    BankName: {
                        required: "必须填写银行名称",
                        rangelength: "银行名称长度必须介于 1 和 40 之间"
                    },
                    SortNo: {
                        required: "必须填写排序",
                        IsPositiveInteger: "必须填写正整数"
                    }
                }
        });
        
    });


    //显示值
    function showBankInfo(id) {

        var cover = FlashPay.UI.Mask({
            obj: $("body"),
            opacity: 0.5
        });

        var BankQuery = {};
        BankQuery.BankCode = id;
        FlashPay.Util.Ajax({
            type: "POST",
            url: "/BankInfo/GetBankInfoByBankCode?BankCode=" + id,
            //data: JSON.stringify(BankQuery),
            dataType: "json",
            contentType: "application/json",
            success: function (data) {
                if (data.data != null) {
                    var infos = data.data;
                    $("#BankCode").attr("disabled", true);
                    FlashPay.Util.SetInputVal("BankCode", infos.bankCode);
                    FlashPay.Util.SetInputVal("BankName", infos.bankName);
                    FlashPay.Util.SetInputVal("BankFullName", infos.bankFullName);
                    FlashPay.Util.SetInputVal("BankEnglishName", infos.bankEnglishName);
                    FlashPay.Util.SetInputVal("BankUrl", infos.bankUrl);
                    $("#BankRemark").val(infos.bankRemark);
                    FlashPay.Util.SetInputVal("BankTel", infos.bankTel);
                    FlashPay.Util.SetInputVal("SortNo", infos.sortNo);
                    $("#BankAddress").val(infos.bankAddress);
                    cover.Remove();
                }
            }
        });
    }

    //保存
    function save() {
        if (!validator.form()) {
            return false;
        }
        var bankInfo = {};
        bankInfo.BankCode = $("input[name='BankCode']").val();
        bankInfo.BankName = $("input[name='BankName']").val();
        bankInfo.BankFullName = $("input[name='BankFullName']").val();
        bankInfo.BankEnglishName = $("input[name='BankEnglishName']").val();
        bankInfo.BankUrl = $("input[name='BankUrl']").val();
        bankInfo.BankRemark = $.trim($("textarea[name='BankRemark']").val());
        bankInfo.BankTel = $("input[name='BankTel']").val();
        bankInfo.SortNo = $("input[name='SortNo']").val();
        bankInfo.BankAddress = $.trim($("textarea[name='BankAddress']").val());

        var url = "/BankInfo/AddBankInfo";
        var id = FlashPay.Util.GetQueryString("id");
        if (id != null && id != undefined) {
            url = "/BankInfo/UpdateBankInfo";
            bankInfo.BankCode = id;
        }

        //document.getElementById("header").scrollIntoView();
        var cover = FlashPay.UI.Mask({
            obj: $("body"),
            opacity: 0.5
        });

        FlashPay.Util.Ajax({
            type: "POST",
            url: url,
            data: { model: bankInfo },
            success: function (data) {
                if (!data.success) {
                    FlashPay.UI.Tip_warning("操作失败!" + data.errorMessage);
                    cover.Remove();
                    return;
                } else {
                    if (FlashPay.Util.isNullOrEmptySpance(id))
                    {
                        cover.Remove();
                        FlashPay.UI.DialogOpener().Tip_success("添加成功!");
                        FlashPay.UI.DialogOpener().doSearch();
                        FlashPay.UI.CloseDialog();
                    }
                    else
                    {
                        cover.Remove();
                        FlashPay.UI.DialogOpener().Tip_success("修改成功!");
                        FlashPay.UI.DialogOpener().doSearch();
                        FlashPay.UI.CloseDialog();
                    }
                }
            },
            error: function (json) {
                cover.Remove();
                FlashPay.UI.Tip_warning("操作失败！请查看网络，请重试。");
            }
        });
    }
</script>
</body>
</html>